package com.nobleoxtechnology.weatherSMS;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;

public class AdvancedSettings implements View.OnClickListener
{
	Context context;
	SharedPreferences preferences;
	Activity activity;
	
	private CheckBox checkboxNotification, checkboxDelete;
	private EditText editTextFilter;
	
	public AdvancedSettings(Context context, Activity activity, SharedPreferences preferences)
	{
		this.context = context;
		this.activity = activity;
		this.preferences = preferences;

		checkboxNotification = (CheckBox) activity.findViewById(R.id.checkBoxBroadcast);
		checkboxDelete = (CheckBox) activity.findViewById(R.id.checkBoxDelete);
		editTextFilter = (EditText) activity.findViewById(R.id.editTextFilter);
		
		checkboxNotification.setChecked(preferences.getBoolean("hideNotification", true));
		checkboxDelete.setChecked(preferences.getBoolean("deleteText", true));
		editTextFilter.setText(preferences.getString("filterText", "Weather:"));
	}
	
	@Override
	public void onClick(View v)
	{
		Editor weatherEditor = preferences.edit();

		weatherEditor.putBoolean("hideNotification", checkboxNotification.isChecked());
		weatherEditor.putBoolean("deleteText", checkboxDelete.isChecked());
		weatherEditor.putString("filterText", editTextFilter.getText().toString());
		
		weatherEditor.commit();
		Toast.makeText(context, "Settings saved successfully!", Toast.LENGTH_LONG).show();
	}
}
